//
//  LLT_HeroViewController_LXM.m
//  CoderLLT
//
//  Created by 刘晓萌 on 15/12/11.
//  Copyright © 2015年 刘晓萌. All rights reserved.
//

#import "LLT_HeroViewController_LXM.h"
#import "LLT_DetailOfArticleModel.h"
#import "LLT_HeroInfoViewController_LXM.h"
#import "DirectionMenubarView.h"
@interface LLT_HeroViewController_LXM ()<UIWebViewDelegate,UIScrollViewDelegate>
@property (weak, nonatomic) IBOutlet UIWebView *webView;
@property (weak, nonatomic) IBOutlet UIWebView *useCountWebView;

@property (weak, nonatomic) IBOutlet UIScrollView *mainScroll;
@property (assign, nonatomic) NSInteger indexScrollFlag;
@property (weak, nonatomic) IBOutlet UIView *directionMenu;
@property (strong, nonatomic) DirectionMenubarView *dicmVC;

@end

@implementation LLT_HeroViewController_LXM

- (void)viewDidLoad {
    [super viewDidLoad];
    [self.webView loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:@"http://static.lolmax.com/api/static/lol/pages/hero/heroList.html"]]];
    [self.useCountWebView loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:@"http://static.lolmax.com/api/static/lol/pages/hero/heroCount.html"]]];
    self.useCountWebView.delegate = self;
    self.webView.delegate = self;
    self.mainScroll.delegate = self;
    self.dicmVC = [DirectionMenubarView instntceWithFrame:CGRectMake(0, 0, WIDTH,35) andTitleArr:(@[@"英雄列表",@"使用次数"].mutableCopy)];
    [self.directionMenu addSubview:self.dicmVC];
    
    __weak typeof(self) __weakSelf = self;
    self.dicmVC.doChang = ^{
        __weakSelf.mainScroll.contentOffset = CGPointMake([__weakSelf.dicmVC getTapedIndex]*WIDTH, __weakSelf.mainScroll.contentOffset.y);
    };
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
}
#pragma mark --- scrollView代理方法和 滑动点击
/*
 * scrollView滑动调用方法
 */
-(void)scrollViewDidScroll:(UIScrollView *)scrollView{
    self.indexScrollFlag = self.mainScroll.contentOffset.x/self.view.frame.size.width;
    [self.dicmVC changTitleWithIndex:self.indexScrollFlag];
}



/**
 * 点击左返回按钮
 */
- (IBAction)didClickLeftBackButton:(UIButton *)sender {
    DissMissBack;
}

/**
 * uiwebView按状态响应加载
 *
 * @return
 */
#pragma mark --- uiwebView 协议
- (BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType
{
    NSString *str = [request URL].absoluteString;
    str = [str stringByReplacingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
    
    NSString *strsub = [str substringToIndex:6];
    NSString *s = @"maxjia://PageConfigJson#/";
    if ([strsub isEqualToString:@"maxjia"]) {
        str =  [str stringByReplacingOccurrencesOfString:s withString:@""];
        NSDictionary *dic = [NSJSONSerialization JSONObjectWithData: [str dataUsingEncoding:NSUTF8StringEncoding]
                                                            options: NSJSONReadingMutableContainers
                                                              error: nil];
        
        LLT_DetailOfArticleModel *heroUrls = [[LLT_DetailOfArticleModel alloc]init];
        [heroUrls setValuesForKeysWithDictionary:dic[@"result"]];
        LLT_HeroInfoViewController_LXM *heroInfoVC = [MainStoryBoard instantiateViewControllerWithIdentifier:@"heroInfoVC"];
        heroInfoVC.heroUrls = heroUrls;
        //NSLog(@"%@",heroUrls.pic);
        [self presentViewController:heroInfoVC animated:YES completion:nil];
    }

    return YES;
}

/**
 * 设置电源栏反颜色
 *
 * @return
 */
- (UIStatusBarStyle)preferredStatusBarStyle
{
    return UIStatusBarStyleLightContent;
}

/*
 #pragma mark - Navigation
 
 // In a storyboard-based application, you will often want to do a little preparation before navigation
 - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
 // Get the new view controller using [segue destinationViewController].
 // Pass the selected object to the new view controller.
 }
 */

@end
